/*
* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
* Description: config头文件
*/
#ifndef UTIL_H
#define UTIL_H

#include <opencv2/core/core.hpp>
#include <opencv2/core/utils/filesystem.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <vector>
#include <iostream>
#include <chrono>
#include <ctime>
#include <sstream>
#include <iomanip>
#include <string>
#include <sys/stat.h>
#include "yaml/haf_yaml.h"

std::string CurrentTimeAndDate();

void Yuv420p2nv12(const cv::Mat &yuv420p, cv::Mat &yuv420_nv12, int32_t width, int32_t height);
int32_t GetFilesBySort(std::string &path, std::vector<std::string> &files, std::string suffix);
time_t ConvertTimeStr2TimeStamp(std::string timeStr);

class FuncTimeMeasure
{
public:
    FuncTimeMeasure(std::string &&descrip);
    ~FuncTimeMeasure();

private:
    std::string description;
    std::chrono::time_point<std::chrono::steady_clock> start {};
    std::chrono::time_point<std::chrono::steady_clock> end {};
};

struct Config {
    std::string dir {""};
    int32_t instanceId {0};
    int32_t width {0};
    int32_t height {0};
};

class ConfigManage
{
public:
    ConfigManage() = default;
    ~ConfigManage() = default;
    ConfigManage(std::string configFile) : file(configFile)
    {}
    void Parse();
    std::vector<Config> GetConfig();
    void Show();
    bool CheckConfig();
    inline static bool FileExist(const std::string &name)
    {
        struct stat buffer;
        return (stat(name.c_str(), &buffer) == 0);
    }
private:
    std::string file {"image_config.yaml"};
    std::vector<Config> configs{};
};
#endif // UTIL_H
